<!--   [PAGE]] : 工程项目信息
       @Author  : ljq
       @Created : 2025/9/26
 -->
<template>
  <div class="app-container">
    <!-- ------------------------ START: 查询框 -------------------------->
    <el-form class='query' :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="项目名称">
        <el-input v-model="queryParams.params.nameLike" placeholder="请输入项目名称" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="用人单位">
        <select-dept v-model="queryParams.employerId" placeholder="请选择用人单位"
                     :query-params="{ parentId: 100 }"
        />
      </el-form-item>
      <el-form-item label="项目地址">
        <el-input v-model="queryParams.address" placeholder="请输入项目地址" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="开工日期">
        <el-date-picker v-model="queryParams.params.startDateRange" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"/>
      </el-form-item>
      <el-form-item label="竣工日期">
        <el-date-picker v-model="queryParams.params.endDateRange"  value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"/>
      </el-form-item>
      <el-form-item label="项目经理">
        <select-user v-model="queryParams.projectManager" placeholder="请选择项目经理"/>
      </el-form-item>
      <el-form-item label="电话">
        <el-input v-model="queryParams.managerPhone" placeholder="请输入电话" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="总预算">
        <el-input v-model="queryParams.totalBudget" placeholder="请输入总预算" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="queryParams.status" placeholder="状态" clearable>
          <el-option v-for="dict in dict.type.business_project_status" :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker v-model="queryParams.params.createTimeRange" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
                        :default-time="['00:00:00', '23:59:59']"/>
      </el-form-item>

      <el-form-item class="option">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- ------------------------- END: 查询框 --------------------------->

    <!-- ---------------------- START: 主数据区域------------------------->
    <el-row :gutter="10" class="mb8" >
      <el-col :span="1.5" v-if="buttonControl.common">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd()" v-hasPermi="['business:project:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5" v-if="buttonControl.common">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['business:project:remove']">批量删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"/>
    </el-row>


    <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="50" align="center"/>
      <el-table-column label="编号" align="center" prop="id" v-if="columns[0].visible"/>
      <el-table-column label="项目名称" align="center" prop="name" v-if="columns[1].visible"/>
      <el-table-column label="用人单位" align="center" prop="employerName" v-if="columns[2].visible">
        <template slot-scope="scope">
          <select-dept isCol  :value="String(scope.row.employerId)"
                       :query-params="{ parentId: 100 }"
          />
        </template>
      </el-table-column>
      <el-table-column label="项目地址" align="center" prop="address" v-if="columns[3].visible"/>
      <el-table-column label="开工日期" align="center" prop="startDate" v-if="columns[4].visible"/>
      <el-table-column label="竣工日期" align="center" prop="endDate" v-if="columns[5].visible"/>
      <el-table-column label="项目经理" align="center" prop="projectManager" v-if="columns[6].visible">
        <template slot-scope="scope">
          <select-user isCol  :value="scope.row.projectManager"/>
        </template>
      </el-table-column>
      <el-table-column label="电话" align="center" prop="managerPhone" v-if="columns[7].visible"/>
      <el-table-column label="总预算" align="center" prop="totalBudget" v-if="columns[8].visible">
        <template slot-scope="scope">
          <el-tag>{{ scope.row.totalBudget/10000 }}万</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" v-if="columns[9].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.business_project_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="卡号" align="center" prop="bankCard.cardId" v-if="columns[10].visible"/>
      <el-table-column label="余额" align="center" prop="bankCard.balance" v-if="columns[11].visible"/>
      <el-table-column label="创建时间" align="center" prop="createTime" v-if="columns[12].visible"/>
      <el-table-column label="创建者" align="center" prop="createName" v-if="columns[13].visible"/>
      <el-table-column label="更新时间" align="center" prop="updateTime" v-if="columns[14].visible"/>
      <el-table-column label="更新者" align="center" prop="updateBy" v-if="columns[15].visible"/>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">

          <!-- 修改按钮 -->
          <el-button
            v-if="buttonControl.common"
            v-hasPermi="[`${permi}:edit`]"
            size="mini"  type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
          >修改</el-button>

          <!-- 删除按钮 -->
          <el-button
            v-if="buttonControl.common"
            v-hasPermi="[`${permi}:remove`]"
            size="mini"  class="delete" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
          >删除</el-button>

          <!-- 详情 -->
          <el-button
            size="mini" type="text" icon="el-icon-s-promotion" @click="toPage(scope.row)"
          >详情
          </el-button>

        </template>
      </el-table-column>


    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList"/>
    <!-- ---------------------- END: 主数据区域 ------------------------>

    <!-- ------------------------ START: 弹出框 -------------------------->
    <el-dialog :title="title" :visible.sync="open" width="780px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="项目名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入项目名称"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="用人单位">
              <select-dept v-model="form.employerId" placeholder="请选择用人单位"
                           :query-params="{ parentId: 100 }"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目地址" prop="address">
              <el-input v-model="form.address" placeholder="请输入项目地址"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开工日期" prop="startDate">
              <el-date-picker clearable v-model="form.startDate" type="date" value-format="yyyy-MM-dd" placeholder="请输入开工日期"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="竣工日期" prop="endDate">
              <el-date-picker clearable v-model="form.endDate" type="date" value-format="yyyy-MM-dd" placeholder="请输入竣工日期"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目经理" prop="projectManager">
              <select-user v-model="form.projectManager" placeholder="请选择项目经理"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="电话" prop="managerPhone">
              <el-input v-model="form.managerPhone" placeholder="请输入电话"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="总预算" prop="totalBudget">
              <el-input v-model="form.totalBudget" placeholder="请输入总预算"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态" prop="status">
              <el-select v-model="form.status" placeholder="状态" clearable>
                <el-option v-for="dict in dict.type.business_project_status" :key="dict.value" :label="dict.label" :value="dict.value"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="银行卡" prop="bankCardId">
              <select-bank-card v-model="form.bankCardId" placeholder="请选择银行卡号"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- ------------------------ END: 弹出框 -------------------------->
  </div>
</template>
<script>
import {listProject, getProject, addProject, updateProject, delProject} from "@/api/business/project";
import {initData, baseMethods} from "@/utils/basePage";

let baseData = initData();
baseData.baseTitle = "项目";
baseData.defaultForm.status = '1';

baseData.queryParams.status = '';
baseData.queryParams.name = '';

export default {
  name: "Project",
  dicts: ['business_project_status'],
  data() {
    return {
      ...baseData,
      permi: 'business:project',

      // 列信息
      columns: [
        {key: 0, label: `编号`, visible: true},
        {key: 1, label: `项目名称`, visible: true},
        {key: 2, label: `用人单位`, visible: true},
        {key: 3, label: `项目地址`, visible: true},
        {key: 4, label: `开工日期`, visible: true},
        {key: 5, label: `竣工日期`, visible: true},
        {key: 6, label: `项目经理`, visible: true},
        {key: 7, label: `电话`, visible: true},
        {key: 8, label: `总预算`, visible: true},
        {key: 9, label: `状态`, visible: true},
        {key: 10, label: `卡号`, visible: true},
        {key: 11, label: `余额`, visible: true},
        {key: 12, label: `创建时间`, visible: false},
        {key: 13, label: `创建者`, visible: false},
        {key: 14, label: `更新时间`, visible: false},
        {key: 15, label: `创建者`, visible: false},

      ],

      // 表单校验
      rules: {
        name: [{required: true, message: "项目名称不能为空", trigger: "blur"}],
        employerId: [{required: true, message: "用人单位不能为空", trigger: "blur"}],
        createBy: [{required: true, message: "创建者不能为空", trigger: "blur"}],
        updateBy: [{required: true, message: "更新者不能为空", trigger: "blur"}],
      },


      // 按钮控制
      buttonControl:{}



    };
  },
  created() {
    const currentUser = this.$store.state.user;
    // this.buttonControl.common = currentUser.roles.includes('master');
    this.buttonControl.common = true;

    this.getList();
  },
  methods: {
    ...baseMethods(listProject, getProject, addProject, updateProject, delProject),

    toPage(param) {
      // 使用路径跳转
      this.$router.push({
        path: '/business/business',
        query: {
          projectId: param.id,
        }
      });
    }


  }


};
</script>
